package iit.projects.etaxi.model.service;

import java.util.TimerTask;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class ProcessCompletedJobsTimerService extends TimerTask {

	final Logger log = LoggerFactory.getLogger(ProcessCompletedJobsTimerService.class);
	
	private VehicleService vehicleService;
	
	@Override
	public void run() {
		if(log.isTraceEnabled()){
			log.trace("Executing Run on ProcessCompletedJobsTimerService");
		}
		
		long startTime = 0;
		startTime = System.currentTimeMillis();
		if(log.isDebugEnabled()){
			log.debug("Started Processing Completed Jobs at " + startTime);
		}
		
		try{
			vehicleService.processFinishedJobs();
		}catch(Throwable e){
			log.error("ERROR : " + e);
		}
		
		if(log.isDebugEnabled()){
			log.debug("Time taken for Processing Completed Jobs = " + 
					(System.currentTimeMillis() - startTime) + "ms");
		}
	}
	public void setVehicleService(VehicleService vehicleService) {
		this.vehicleService = vehicleService;
	}

}
